package org.liao.springboot.webservice.ws.client;

import org.apache.cxf.Bus;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.io.IOException;
import java.net.URL;

public class JDKWsServiceClient {
    public static void main(String[] args) throws IOException {
        //创建WSDL文件的URL
        URL wsdlDocumentLocation=new URL("http://localhost:1899/weather?wsdl");
        //创建服务名称
        //1.namespaceURI - 命名空间地址
        //2.localPart - 服务视图名
        QName serviceName=new QName("http://service.ws.webservice.springboot.liao.org/","WeatherService");
        Service service=Service.create(wsdlDocumentLocation, serviceName);

        //获取服务实现类
        QName servicePortName=new QName("http://service.ws.webservice.springboot.liao.org/","WeatherPort");
        WeatherInterClientFace mobileCodeWSSoap= service.getPort(servicePortName,WeatherInterClientFace.class);
        //调用方法
        WeatherInfoClientReq weatherInfoReq=new WeatherInfoClientReq();
        weatherInfoReq.setCity("三门峡");
        weatherInfoReq.setSendTime(System.currentTimeMillis());
        WeatherInfoClientResp resp = mobileCodeWSSoap.getWeatherByCity(weatherInfoReq);
        System.out.println("Server said: " + resp);
    }
}
